package com.ptszyxx.popose.module.main.user.adapter;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.databinding.ItemUserEditLabelBinding;
import com.ptszyxx.popose.module.main.user.vm.UserEditLabelVM;
import com.ysg.http.data.entity.user.LabelItemEntity;
import com.ysg.utils.YStringUtil;
import com.ysg.utils.YToastUtil;

public class UserEditLabelAdapter extends BaseQuickAdapter<LabelItemEntity, BaseDataBindingHolder<ItemUserEditLabelBinding>> {

    private UserEditLabelVM viewModel;

    public UserEditLabelAdapter(UserEditLabelVM viewModel) {
        super(R.layout.item_user_edit_label);
        this.viewModel = viewModel;
    }

    @Override
    protected void convert(@NonNull BaseDataBindingHolder<ItemUserEditLabelBinding> holder, LabelItemEntity item) {
        ItemUserEditLabelBinding binding = holder.getDataBinding();
        if (binding != null) {
            binding.executePendingBindings();
            binding.tvLabel.setText(item.getName());

            if(YStringUtil.eq(1, item.getIsselect())){
                binding.tvLabel.setBackgroundResource(R.drawable.shape_label_select_bg);
                binding.tvLabel.setTextColor(getContext().getResources().getColor(com.ysg.R.color.white));
            }else {
                binding.tvLabel.setBackgroundResource(R.drawable.shape_label_bg);
                binding.tvLabel.setTextColor(getContext().getResources().getColor(com.ysg.R.color.black));
            }

            binding.tvLabel.setOnClickListener((view)->{
                if (viewModel.selectNum >= 15 && YStringUtil.noEq(1, item.getIsselect())){
                    YToastUtil.showShort(R.string.user_edit_label_num_tip);
                    return;
                }
                if (YStringUtil.eq(1, item.getIsselect())){
                    item.setIsselect(2);
                    viewModel.selectNum--;
                }else{
                    item.setIsselect(1);
                    viewModel.selectNum++;
                }
                viewModel.onSelectNum();
                notifyDataSetChanged();
            });
        }
    }









}
